#pragma once
#include "ConfigIni.h"
#include "Define.h"
#include "GlueTestDlg.h"
#include "GlueTest.h"
#include "SocketClient.h"
using namespace cv;
class CSystemManager
{
public:
	CSystemManager();
	~CSystemManager();

	BYTE startflag_PLC;
	BYTE ProgramNum;
	BYTE LightFlag = true;
	BYTE writebyte_PLC;
	BYTE barcode_PLC[20][100];
	BYTE mybufX[4];
	BYTE mybufY[4];
	BYTE mybufT[4];
	BYTE mybufCX[4];
	BYTE mybufCY[4];
	BYTE mybufCT[4];


	bool m_bGlueTestStart;
//	bool GlueTestResule = false;
	BYTE ImgSaveFlag = 0;
	float toorque[3] = { 0 };
	CWnd*   m_ptrMainUI;
	CWnd*   m_ptrTcpIpUI;

	CString GlueTestAcceptMes;
	CString m_cstrSn;
	vector<wstring> vResultItem;

	CString GetCurrentExePath();
	void GeneralSettingIniInit();
	void CameraSettingIniInit();
	void ReadGeneralSettingIni();
	void SystemInfIniInit();
	void TcpConfigInit();
	void ReadTcpIpIni();
	void LoginConfigIniInit();
	void ReadLoginConfigIni();
	void GlueTestConfigIniInit();
	void ReadGlueTestConfigIni();
	void ReadCamInfIni();
	void ShowImage(Mat & src, CWnd* hdlg, UINT ID);
	void StartTcpipRecvThread();
	unsigned int __stdcall TcpipRecvThread();
	void StartGlueTestThread();
	void StartTestTimeoutThread();
	unsigned int __stdcall TestTimeoutThread();
	unsigned int __stdcall GlueTestThread();

	int SaveTestResult(const CString & cSnCode, int nResult, const Mat & matImage, const Mat & matImageOrg);
	int SaveTestMatImg(const CString & cSnCode, const Mat & matImageOrg);
	int SaveMes(const CString & cSnCode, int nResult);
	int CreateMesFile(const char * test_item_str, char * target_report_folder_path, char * target_folder_name);
	int m_nGlueTestResult;
	bool m_nGlueTesting;
	void TcpIpConnect();
	void TcpIpSendMessage();
	CFont m_logFont;
	CConfigIni m_cGeneralSetting;
	CConfigIni m_cSystemConfigIni;
	CConfigIni m_cCameraSetting;
	CConfigIni m_cTrayGuideInf;
	CConfigIni m_cTcpConfigIni;
	CConfigIni m_cGlueTestInf;
	GENERAL_SETTING m_sGeneralSetting;
	LOGIN_INFO m_sLoginInfo;
	CConfigIni m_cLoginConfigIni;
	std::vector<HANDLE> m_vWorkerThread;
	union UI_Proc
	{
		unsigned(_stdcall * ThreadProc)(void*);
		unsigned(_stdcall CSystemManager::*MemProc)();
	}PCBMatch, ProcTcpipRelink, PlcLink, PlcLinkCheck, TrayGuide,TcpRecv,GlueTimeout;
	HANDLE hThread_PCBMatch;
	MAINDLG_INF m_maindlgInf;
	CAMERA_INF m_sCameraInf;
	TCPIP_INF m_sTcpIpInf;
	GLUE_TEST m_sGlueTest;
	Mat m_matImage;
	Mat m_matImageS;
	Mat m_matShow;
	Mat m_matTemplateS;
	Mat m_matTemplate[2];
	Mat m_matTrayGuide;
	Mat m_matImage_2;

	IplImage* SrcImg11 = NULL;

	CTcpIp m_cTcpIp;
	CGigECam m_cGigeCam;
	CGlueTest m_cGlueTest;
	CGlueTestDlg m_cGlueTestDlg;

	int CatchFlag = 0;
	int CameraFlag = 0;
private:

	int result = 0;
	float m_fScreenX = 0.0f;
	float m_fScreenY = 0.0f;
	const int UI_SCREEN_X = 1280;
	const int UI_SCREEN_Y = 1024;

};

